﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace LowLevelGraphics.Filter
{
    /// <summary>
    /// 
    /// </summary>
    public class Shear : BaseImageFilter
    {
        protected float m_Steigung = 1.0f;
        protected float m_Constant = 3.0f;

        /// <summary>
        /// Initializes a new instance of the <see cref="Shear"/> class.
        /// </summary>
        public Shear()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Shear"/> class.
        /// </summary>
        /// <param name="_shear">The _shear.</param>
        internal Shear(Shear _shear)
        {
        }

        /// <summary>
        /// Execute this Filter
        /// A Debug Statement is written if a concrete Filter is called
        /// </summary>
        /// <param name="_bitmap"></param>
        /// <returns></returns>
        public override UnsafeBitmap Execute(UnsafeBitmap _bitmap)
        {
            UnsafeBitmap bitmapCloned = (UnsafeBitmap)_bitmap.Clone();
            int nWidth = _bitmap.Width;
            int nHeight = _bitmap.Height;
            int x = 0;
            int y = 0;
            for (y = 0; y < nHeight; y++)
            {
                for (x = 0; x < nWidth; x++)
                {
                    int nx = x;
                    int ny = y;
                    ny = (int)((float)(m_Steigung * x + m_Constant));
                    if (nx < nWidth && ny < nHeight)
                    {
                        Color color = bitmapCloned.GetPixel(nx, y);
                        _bitmap.SetPixel(nx, ny, color);
                    }
                }
            }
            return _bitmap;
        }

        /// <summary>
        /// This is used to clone a filter, each filter must implement it's own clone functionality
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new Shear(this);
        }
    }
}
